package com.geeaks.learn.java8;

import java.util.concurrent.CompletableFuture;

public class Main {
	
	public static void main(String[] args) {
		Runnable noArguments = () -> {
			System.out.println("Hello World");
			System.out.println("Hello World");
			};
//		noArguments.run();
	}
	
	static void thenApplyExample() {
		CompletableFuture<String> cf = CompletableFuture.completedFuture("message").thenApply(s -> {
			System.out.println(Thread.currentThread().isDaemon());
			return s.toUpperCase();
		});
		System.out.println(cf.getNow(null));
	}
	
	static void runAsyncExample() {
		CompletableFuture<Void> cf = CompletableFuture.runAsync(() -> {
			try {
				Thread.sleep(3000L);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println("是否守护线程：" + Thread.currentThread().isDaemon());
		});
		while (!cf.isDone()) {
			try {
				Thread.sleep(1000L);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println(cf.isDone());
		}
	}
	
	static void completedFutureExample() {
		CompletableFuture<String> cf = CompletableFuture.completedFuture("message");
		System.out.println(cf.isDone());
		System.out.println(cf.getNow(null));
	}
	
	static void test() {
		String s = new String("1");
		s.intern();
		String s2 = "1";
		System.out.println(s == s2);
		String s3 = new String("1") + new String("1");
		s3.intern();
		String s4 = "11";
		System.out.println(s3 == s4);
	}
}
